package base.config.lib;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Properties;


/**
 * 获取数据库配置信息 单实例
 * 
 * @author admin
 * 
 */
public class MSNJOBConfig {
	private String db_driverclass = "";
	private String db_username = "";
	private String db_password = "";
	private String db_jdbcurl="";
	private String mail_smtp_auth="true";
	private String mail_transport_protocol="smtp";
	private String mail_smtp_host="smtp.163.com";
	private String mail_username="dongjiantang@163.com";
	private String mail_password="******";
    private static MSNJOBConfig instance = null;
	private Properties configProperties=null;

	private MSNJOBConfig() {

	}

	public static MSNJOBConfig getInstance() throws Exception {
		if (instance == null) {
			instance = new MSNJOBConfig();
			String filepath = "";
			filepath = instance.getClassPath() + "msnjobconfig.properties";
			File file = new File(filepath);
			Properties prop = new Properties();
			InputStream fis = new FileInputStream(file);
		    prop.load(fis);
	        //加载配置信息
		   instance.setConfigProperties(prop);
		   instance.setDb_driverclass(prop.getProperty("db.driverclass"));
		   instance.setDb_jdbcurl(prop.getProperty("db.jdbcurl"));
		   instance.setDb_username(prop.getProperty("db.username"));
		   instance.setDb_password(prop.getProperty("db.password"));
		   instance.setMail_smtp_auth(prop.getProperty("mail.smtp.auth"));
		   instance.setMail_transport_protocol(prop.getProperty("mail.transport.protocol"));
		   instance.setMail_smtp_host(prop.getProperty("mail.smtp.host"));
		   instance.setMail_username(prop.getProperty("mail.username"));
		   instance.setMail_password(prop.getProperty("mail.password"));

		   //关闭流
		   fis.close();
		   System.out.println("**************读取配置信息***************");		   
		}
		return instance;
	}


	public String getDb_driverclass() {
		return db_driverclass;
	}

	public void setDb_driverclass(String dbDriverclass) {
		db_driverclass = dbDriverclass;
	}

	public String getDb_username() {
		return db_username;
	}

	public void setDb_username(String dbUsername) {
		db_username = dbUsername;
	}

	public String getDb_password() {
		return db_password;
	}

	public void setDb_password(String dbPassword) {
		db_password = dbPassword;
	}

	public String getDb_jdbcurl() {
		return db_jdbcurl;
	}

	public void setDb_jdbcurl(String dbJdbcurl) {
		db_jdbcurl = dbJdbcurl;
	}

	public String getMail_smtp_auth() {
		return mail_smtp_auth;
	}

	public void setMail_smtp_auth(String mailSmtpAuth) {
		mail_smtp_auth = mailSmtpAuth;
	}

	public String getMail_transport_protocol() {
		return mail_transport_protocol;
	}

	public void setMail_transport_protocol(String mailTransportProtocol) {
		mail_transport_protocol = mailTransportProtocol;
	}

	public String getMail_smtp_host() {
		return mail_smtp_host;
	}

	public void setMail_smtp_host(String mailSmtpHost) {
		mail_smtp_host = mailSmtpHost;
	}

	public String getMail_username() {
		return mail_username;
	}

	public void setMail_username(String mailUsername) {
		mail_username = mailUsername;
	}

	public String getMail_password() {
		return mail_password;
	}

	public void setMail_password(String mailPassword) {
		mail_password = mailPassword;
	}

	public Properties getConfigProperties() {
		return configProperties;
	}

	public void setConfigProperties(Properties configProperties) {
		this.configProperties = configProperties;
	}

	/**
	 * 获得ClassPath的路径.
	 * 
	 * @return String 路径字符串
	 */
	public String getClassPath() {

		URL url = this.getClass().getResource("/");
		String path = null;

		try {
			path = URLDecoder.decode(url.getPath(), "UTF-8");
		} catch (IOException e) {
			e.printStackTrace();
		}

		return path;
	}

}
